package cn.edu.hyit.zhao.entity;

import java.sql.Timestamp;
import java.util.Map;

/**
 * 日志实体类
 * 
 * @author Neko
 * @version 1.0
 * @date 2016-01-04
 * 
 */
public class Log extends DataModule {
    private Integer id;
    private String type; // 日志类型
    private String user; // 操作用户
    private String remoteAddr; // 操作用户的IP地址
    private String requestUri; // 操作的URI
    private String method; // 操作提交的方式
    private String params; // 提交的数据
    private String userAgent; // 操作用户代理信息
    private String exception; // 异常信息
    private Timestamp createTime; // 日志创建时间

    // 日志类型（1.接入日志 2.错误日志）
    public static final String TYPE_ACCESS = "1";
    public static final String TYPE_EXCEPTION = "2";

    public Log() {
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Timestamp getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Timestamp createTime) {
        this.createTime = createTime;
    }

    public String getUser() {
        return user;
    }

    public void setUser(String user) {
        this.user = user;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getRemoteAddr() {
        return remoteAddr;
    }

    public void setRemoteAddr(String remoteAddr) {
        this.remoteAddr = remoteAddr;
    }

    public String getRequestUri() {
        return requestUri;
    }

    public void setRequestUri(String requestUri) {
        this.requestUri = requestUri;
    }

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public String getParams() {
        return params;
    }

    public void setParams(String params) {
        this.params = params;
    }

    // 获取Map中的参数
    @SuppressWarnings({ "rawtypes", "unchecked" })
    public void setParams(Map paramMap) {
        if (paramMap == null) {
            return;
        }
        StringBuilder params = new StringBuilder();
        for (Map.Entry<String, String[]> param : ((Map<String, String[]>) paramMap).entrySet()) {
            params.append(("".equals(params.toString()) ? "" : "&") + param.getKey() + "=");
            String paramValue = (param.getValue() != null && param.getValue().length > 0 ? param.getValue()[0] : "");
            params.append(paramValue);
        }
        this.params = params.toString();
    }

    public String getUserAgent() {
        return userAgent;
    }

    public void setUserAgent(String userAgent) {
        this.userAgent = userAgent;
    }

    public String getException() {
        return exception;
    }

    public void setException(String exception) {
        this.exception = exception;
    }

}
